/*
 * Copyright 2011 Subhabrata Ghosh <subho.ghosh at langene.net>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



package net.langene.nlp.model.en;

//~--- non-JDK imports --------------------------------------------------------

import net.langene.nlp.model.EnumPosType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

//~--- enums ------------------------------------------------------------------

/**
 * Parts-Of-Speech Enum - Defines POS tags based on the
 * Penn TreeBank set. Some extensions added to make is compatible with
 * the OpenANC tags.
 *
 * @author Subhabrata Ghosh <subho.ghosh at langene.net>
 */
public enum EnumPOS {

    /**
     * Coordinating conjunction
     */
    CC(0),

    /**
     * Cardinal number
     */
    CD(1),

    /**
     * Determiner
     */
    DT(2),

    /**
     * Existential there
     */
    EX(3),

    /**
     * Foreign word
     */
    FW(4),

    /**
     * Preposition or subordinating conjunction
     */
    IN(5),

    /**
     * Adjective
     */
    JJ(6),

    /**
     * Adjective, comparative
     */
    JJR(7),

    /**
     * Adjective, superlative
     */
    JJS(8),

    /**
     * List item marker
     */
    LS(9),

    /**
     * Modal
     */
    MD(10),

    /**
     * Noun, singular or mass
     */
    NN(11),

    /**
     * Noun, plural
     */
    NNS(12),

    /**
     * Proper noun, singular
     */
    NNP(13),

    /**
     * Proper noun, plural
     */
    NNPS(14),

    /**
     * Predeterminer
     */
    PDT(15),

    /**
     * Possessive ending
     */
    POS(16),

    /**
     * Personal pronoun
     */
    PRP(17),

    /**
     * Possessive pronoun
     */
    PRP$(18),

    /**
     * Adverb
     */
    RB(19),

    /**
     * Adverb, comparative
     */
    RBR(20),

    /**
     * Adverb, superlative
     */
    RBS(21),

    /**
     * Particle
     */
    RP(22),

    /**
     * Symbol
     */
    SYM(23),

    /**
     * to
     */
    TO(24),

    /**
     * Interjection
     */
    UH(25),

    /**
     *  Verb, base form
     */
    VB(26),

    /**
     * Verb, past tense
     */
    VBD(27),

    /**
     * Verb, gerund or present participle
     */
    VBG(28),

    /**
     * Verb, past participle
     */
    VBN(29),

    /**
     * Verb, non- person singular present
     */
    VBP(30),

    /**
     *  Verb,  person singular present
     */
    VBZ(31),

    /**
     * Wh-determiner
     */
    WDT(32),

    /**
     * Wh-pronoun
     */
    WP(33),

    /**
     * Possessive wh-pronoun
     */
    WP$(34),

    /**
     * Wh-adverb
     */
    WRB(35),

    /**
     * Sentence Termination .?
     */
    DOT(36),

    /**
     * Brackets
     */
    BR(37),

    /**
     * Quotes
     */
    QT(38),

    /**
     * Seperators ,:; etc
     */
    SEP(39),

    /**
     * Exclamation
     */
    EXC(40),

    /**
     * Other Symbols
     */
    OSYM(41)
    ;

    private static Logger	_logger = LoggerFactory.getLogger(EnumPOS.class);

    //~--- fields -------------------------------------------------------------

    private int	value = -1;

    //~--- constructors -------------------------------------------------------

    private EnumPOS(int value) {
        this.value = value;
    }

    //~--- methods ------------------------------------------------------------

    /**
     * Get the integer value associated with this Enum.
     * 
     * @return
     */
    public int value() {
        return value;
    }

    /**
     * Parse the POS Enum. The regular Enum.valueOf will not work because
     * there are special cases where characters are used to represent the POS.
     *
     * @param word - Current word
     * @param pos - Current POS String
     * @return Parsed Enum
     * @throws Exception
     */
    public static EnumPOS parseEnum(String word, String pos) throws Exception {
        try {
            return EnumPOS.valueOf(pos);
        } catch (IllegalArgumentException iae) {
            if (pos.matches("\\W*")) {
                return OSYM;
            }
        }

        throw new IllegalAccessException("Invalid POS : [" + pos + "][" + word
                                         + "}, doesnot exists in the Enum.");
    }

    //~--- get methods --------------------------------------------------------

    /**
     * Get an abstract Type of the POS.
     *
     * @return
     */
    public EnumPosType getType() {
        if (this.name().startsWith("NN")) {
            return EnumPosType.ENTITY;
        } else if ((this == PRP) || (this == PRP$)) {
            return EnumPosType.ENTITY;
        } else if (this.name().startsWith("VB")) {
            return EnumPosType.ACTION;
        }

        return EnumPosType.OTHER;
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
